package com.eneat.smartrule.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.eneat.smartrule.enums.LogicEnum;
import com.eneat.smartrule.enums.ComparisonOperatorEnum;
import com.eneat.smartrule.handler.ListTypeHandler;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class RuleCondition extends BaseModel {

    @Schema(description = "关联的规则id")
    private Long ruleId;

    @Schema(description = "父id")
    private Long parentId;

    @Schema(description = "字段名")
    private String field;

    @Schema(description = "操作符，来源于OperatorEnum枚举")   // 可以是 '==', '>', '<' 等
    private ComparisonOperatorEnum operator;

    @Schema(description = "值，就是字段的值,大部分清空可能只有一个，就传一个就好了，暂时搞不懂为什么是个list")
    @TableField(typeHandler = ListTypeHandler.class, value = "field_value")
    private List<String> fieldValue;

    @Schema(description = "自定义函数")
    private String customFunction;

    @Schema(description = "布尔逻辑，来源于LogicEnum枚举") // 可以是 "&&" 或 "||"
    private LogicEnum logic;

    @Schema(description = "前缀")
    private String prefix;

    @Schema(description = "值是否被引号包围，如果是string类型的就需要，比如int类型就不需要，这和value的类型无关。自己判断")
    private Boolean isValueQuoted = false;

    @Schema(description = "子条件")
    @TableField(exist = false)
    private List<RuleCondition> subRuleConditions;

    @Schema(description = "算术表达式链")
    @TableField(typeHandler = ListTypeHandler.class, value = "arithmetic_expressions")
    private List<ArithmeticExpression> arithmeticExpressions;

    @Schema(description = "是否需要括号包围，有两个作用，若没有子条件，则是为了直观，若有自条件，括号表示优先级")
    private boolean isBracketed;

    @Schema(description = "表达式,存在则直接运用，不解析")
    private String Expression;

    @Schema(description = "命中后的动作，暂时不启用，后面补充")
    @TableField(exist = false)
    private RuleAction ruleAction;
}
